package com.dragee.modules.officialWebsite.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragee.common.PageUtils;
import com.dragee.constants.CommonConstants;
import com.dragee.modules.officialWebsite.dao.LinkAboutDao;
import com.dragee.modules.officialWebsite.entity.LinkAboutEntity;
import com.dragee.modules.officialWebsite.service.LinkAboutService;
import com.dragee.modules.sys.entity.FilesEntity;
import com.dragee.utils.UploadUtil;
import com.dragee.utils.WrapperUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service("linkAboutService")
public class LinkAboutServiceImpl extends ServiceImpl<LinkAboutDao, LinkAboutEntity> implements LinkAboutService {


    @Resource
    private LinkAboutDao linkAboutDao;

    private String business = "linkAbout";
    /**
    * 列表
    */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        int limit = params.get(CommonConstants.LIMIT) == null
                ?CommonConstants.LIMIT_SIZE:Integer.parseInt(params.get(CommonConstants.LIMIT).toString());
        int start = params.get(CommonConstants.START) == null
                ?CommonConstants.START_SIZE:Integer.parseInt(params.get(CommonConstants.START).toString());
        QueryWrapper<LinkAboutEntity> wrapper =
                WrapperUtil.getWrapper(business, params, LinkAboutEntity.class);
        IPage<LinkAboutEntity> page = new Page<>(start, limit);
        page = baseMapper.selectPage(page, wrapper.select());
        for (LinkAboutEntity record : page.getRecords()) {
            FilesEntity files = UploadUtil.getFilesEntity(record.getFileId());
            if (files != null) {
                record.setFileName(files.getFileName());
                record.setFilePath(files.getFilePath());
            }
        }
        return new PageUtils(page);
    }
}